﻿#region Namespace References

using System;
using DynConDevCorp.OpenArch.SmartData.BillingDemo1.ApplicationBusinessObjects;
using DynConDevCorp.OpenArch.SmartData.Core;
using DynConDevCorp.OpenArch.SmartData.Interfaces.Attributes;
using DynConDevCorp.OpenArch.SmartData.WinForms;

#endregion

namespace DynConDevCorp.OpenArch.SmartData.BillingDemo1.SmartUIControls
{
    public partial class OrderSummaryControl : SmartEntityControl
    {
      #region Constructors

        public OrderSummaryControl()
        {
            InitializeComponent();
            bmcEntity.BoundEntityChanged += bmcEntity_BoundEntityChanged;  
            Order = new SmartEntityLink<Order>();
            Order.LinkedEntityChanged += Order_LinkedEntityChanged;
        }

        #endregion

        #region Public Instance Properties

        [AutoField]
        public SmartEntityLink<Order> Order { get; set; }

        #endregion

        #region Public Instance Methods

        private void bmcEntity_BoundEntityChanged(object sender, EventArgs e)
        {
            Order boundOrder = (Order) bmcEntity.BoundEntity;
            Order.LinkedEntity = boundOrder;
        }

        private void Order_LinkedEntityChanged(object sender, EventArgs e)
        {
            bmcOrders.BoundEntity = Order.LinkedEntity;
        }

        #endregion
    }
}